package org.example.onetry.servlet;

import jakarta.servlet.GenericServlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public class cookieweite extends GenericServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        //通过响应对象将cookie存入浏览器，cookie存字符串
        Cookie cookie=new  Cookie("cookie","cookie");
        //设置cookie最大存活时间为1800s,过了就会销毁
        cookie.setMaxAge(1800);
        response.addCookie(cookie);
    }
}
